package com.link.base.base.system.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 存储parentid或subid的父子结构构造树形结构的节点类
 *
 * @author LiYang
 * @date 2019-12-11
 **/
public class TreeNode implements Serializable {

    public TreeNode() {

    }

    public TreeNode(Long id, Long parentId, String name, String parentName,
                    String code, String parentCode, String dataType, String originType) {
        this.id = id;
        this.parentId = parentId;
        this.name = name;
        this.parentName = parentName;
        this.code = code;
        this.parentCode = parentCode;
        this.dataType = dataType;
        this.originType = originType;
    }

    public TreeNode(Long id, Long parentId, String name, String parentName) {
        this.id = id;
        this.parentId = parentId;
        this.name = name;
        this.parentName = parentName;
    }

    /**
     * id
     */
    private Long id;

    /**
     * 父id
     */
    private Long parentId;

    /**
     * 名称
     */
    private String name;

    /**
     * 父名称
     */
    private String parentName;

    /**
     * 编码
     */
    private String code;

    /**
     * 父编码
     */
    private String parentCode;

    /**
     * 数据类型
     */
    private String dataType;

    /**
     * 基础表原始类型字段，类似org_type，postn_type等
     */
    private String originType;

    /**
     * 弹性字段2
     */
    private String attribute2;

    /**
     * 弹性字段3
     */
    private String attribute3;

    /**
     * 节点深度
     */
    private Integer deep;

    /**
     * 节点列表
     */
    private List<TreeNode> subs;

    /**
     * 父节点
     */
    private TreeNode parent;

    /**
     * 根节点id
     */
    private Long rootId;

    /**
     * lnk_party_rel表中的sub_party_id与party_id的组合字段，用“-”连接
     */
    private String combinationId;

    /**
     * 操作标识。0：不动，1：新建，2：修改
     */
    private Integer operation;

    /**
     * 这个字段只在处理party_rel时有用，用来存储lnk_party_rel表的row_id字段
     */
    private String rowId;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public String getOriginType() {
        return originType;
    }

    public void setOriginType(String originType) {
        this.originType = originType;
    }

    public String getAttribute2() {
        return attribute2;
    }

    public void setAttribute2(String attribute2) {
        this.attribute2 = attribute2;
    }

    public String getAttribute3() {
        return attribute3;
    }

    public void setAttribute3(String attribute3) {
        this.attribute3 = attribute3;
    }

    public Integer getDeep() {
        return deep;
    }

    public void setDeep(Integer deep) {
        this.deep = deep;
    }

    public List<TreeNode> getSubs() {
        return subs;
    }

    public void setSubs(List<TreeNode> subs) {
        this.subs = subs;
    }

    public TreeNode getParent() {
        return parent;
    }

    public void setParent(TreeNode parent) {
        this.parent = parent;
    }

    public Long getRootId() {
        return rootId;
    }

    public void setRootId(Long rootId) {
        this.rootId = rootId;
    }

    public String getCombinationId() {
        return combinationId;
    }

    public void setCombinationId(String combinationId) {
        this.combinationId = combinationId;
    }

    public Integer getOperation() {
        return operation;
    }

    public void setOperation(Integer operation) {
        this.operation = operation;
    }

    public String getRowId() {
        return rowId;
    }

    public void setRowId(String rowId) {
        this.rowId = rowId;
    }

    /**
     * 添加一个子节点
     *
     * @author LiYang
     * @date 2019-12-11
     * @param subNode
     **/
    public void addSubNode(TreeNode subNode) {
        if (null == subs) {
            subs = new ArrayList<>(8);
        }
        subs.add(subNode);
    }

    /**
     * 批量添加子节点
     *
     * @author LiYang
     * @date 2019-12-11
     * @param subList
     */
    public void addSubs(List<TreeNode> subList) {
        if (null == subs) {
            subs = new ArrayList<>(8);
        }
        subs.addAll(subList);
    }

    /**
     * 判断是否为叶子节点
     *
     * @author LiYang
     * @date 2019-12-11
     * @param
     **/
    public boolean isEndNode() {
        if (null == subs || subs.isEmpty()) {
            return true;
        }
        return false;
    }
}
